package org.lee.mq.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * @author jackielee
 * @version 1.0
 * @description JsonUtil
 * @date 2021/7/2
 **/
public class JsonUtil {

    public static String toJson(Object obj) {
        return new Gson().toJson(obj);
    }

    private static Gson build() {
        return new GsonBuilder().generateNonExecutableJson()
                .create();
    }

    public static <T> T fromJson(String json, Class<T> clazz) {
        return new Gson().fromJson(json, clazz);
    }

    public static <T> T fromJsonCollect(String json, Class<T> clazz) {
        return new Gson().fromJson(json, new TypeToken<T>() {
        }.getType());
    }
}
